package recipe.renderer;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class RecipeListAdapter extends ArrayAdapter<Recipe> {
	private Recipe[] recipes = null;
	private int layoutResourceID;
	public Context context;
	
    public RecipeListAdapter(Context context, int layoutID, Recipe[] newRecipes) 
    {
        super(context,layoutID,newRecipes);
    	this.layoutResourceID = layoutID;
        this.context = context;
        this.recipes = newRecipes;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        RecipeHolder holder = null;
        
        if (row == null) {
        	  	LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        	  	row = inflater.inflate(layoutResourceID, parent, false);                
        	  	
        	  	holder       = new RecipeHolder();
                holder.image = (ImageView) row.findViewById(R.id.icon);
                holder.text  = (TextView)  row.findViewById(R.id.label);
                row.setTag(holder);
        }else {
        	holder = (RecipeHolder)(row.getTag());
        }

        holder.text.setText(recipes[position].title);
//        holder.image.setImageResource(android.graphics.Bitmap.	)
        return row;
}
    
static class RecipeHolder
{
    ImageView image;
    TextView  text;
}

	
}
